package wtflog

import (
	"sync"

	. "gitee.com/FlyingOnion/wtflog/types"
)

var (
	bufferSize    = 64
	maxBufferSize = 16 * bufferSize

	bpool = sync.Pool{New: func() interface{} {
		return NewByteSlice(make([]byte, 0, bufferSize))
	}}
)

func newBuffer() *ByteSlice {
	if b, ok := bpool.Get().(*ByteSlice); ok && b.Len() == 0 {
		return b
	}
	return NewByteSlice(make([]byte, 0, bufferSize))
}

func recycleBuffer(b *ByteSlice) {
	if b.Cap() <= maxBufferSize {
		b.Reset()
		bpool.Put(b)
	}
}
